using System;
using System.Linq.Expressions;


namespace Cassandraemon.Util
{

	static class ExpressionChecker
	{
		public static bool IsCassandraEntityMemberAccess(Expression expression)
		{
			if(expression == null) return false;
			if(expression.NodeType != ExpressionType.MemberAccess) return false;
			
			MemberExpression member = expression as MemberExpression;
			if(member == null) return false;
			
			if(member.Member.DeclaringType.Name != "CassandraEntity`1") return false;
			
			return true;
		}
		
		public static bool IsCassandraEntityIndexAccess(Expression expression)
		{
			if(expression == null) return false;
			if(expression.NodeType != ExpressionType.Call) return false;
			
			MethodCallExpression method = expression as MethodCallExpression;
			MemberExpression member = method.Object as MemberExpression;
			
			if(method == null) return false;
			if(member == null) return false;
			
			if(method.Method.Name != "get_Item") return false;
			if(member.Member.Name != "Index") return false;
			if(member.Expression.Type.Name != "CassandraEntity`1") return false;
			
			return true;
		}
	}
}
